using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;

namespace CurriculaAPI.POCOModel
{
    public partial class CurriculaEntity : DbContext
    {
        public CurriculaEntity()
            : base("name=CurriculaEntity")
        {
        }

        public virtual DbSet<CategoryName> CategoryName { get; set; }
        public virtual DbSet<CourseName> CourseName { get; set; }
        public virtual DbSet<Professor> Professor { get; set; }
        public virtual DbSet<StudentInfo> StudentInfo { get; set; }
        public virtual DbSet<TitleName> TitleName { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<CategoryName>()
                .HasMany(e => e.Professor)
                .WithRequired(e => e.CategoryName1)
                .HasForeignKey(e => e.CategoryName)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<CourseName>()
                .HasMany(e => e.Professor)
                .WithRequired(e => e.CourseName1)
                .HasForeignKey(e => e.CourseName)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Professor>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<Professor>()
                .Property(e => e.Avatar)
                .IsUnicode(false);

            modelBuilder.Entity<StudentInfo>()
                .Property(e => e.PhoneNum)
                .IsUnicode(false);

            modelBuilder.Entity<StudentInfo>()
                .Property(e => e.Password)
                .IsUnicode(false);

            modelBuilder.Entity<StudentInfo>()
                .Property(e => e.Pwd)
                .IsUnicode(false);

            modelBuilder.Entity<StudentInfo>()
                .Property(e => e.Address)
                .IsUnicode(false);

            modelBuilder.Entity<TitleName>()
                .HasMany(e => e.Professor)
                .WithRequired(e => e.TitleName1)
                .HasForeignKey(e => e.TitleName)
                .WillCascadeOnDelete(false);
        }
    }
}
